# @Time    : 2022/7/16 9:54
# @Author  : mobai
# @Email   : 3111283671@qq.com
# @File    : tjsj_page.py
# @Software: PyCharm

import unittest
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from pages.base_pageage import BasePage
from selenium.webdriver.support.select import Select
from pages.shangji_page import ShangJiPage


class TjsjPage(ShangJiPage):
    """添加商机"""
    url = "http://192.168.1.151/crm/index.php?m=business&a=add"
    SJM = (By.ID, "name")
    XZKH = (By.ID, "customer_name")
    GXKH = (By.CSS_SELECTOR, "#datas > tr > td:nth-child(1) > input[type=radio]:nth-child(1)")
    QD = (By.XPATH, "/html/body/div[10]/div[3]/div/button[1]/span")
    SJJE = (By.ID, "total_price")
    LX = (By.ID, "type")
    XZZT = (By.ID, "status_id")
    LY = (By.ID, "origin")
    YDL = (By.ID, "gain_rate")
    YJCJ = (By.ID, "estimate_price")
    LXSJ = (By.ID, "nextstep_time")
    LXNR = (By.ID, "nextstep")
    BZ = (By.ID, "description")
    DJBC = (By.CSS_SELECTOR, "#form1 > table > tfoot > tr > td > input:nth-child(1)")

    def sjm(self,sjm):
        """输入商机名"""
        self.driver.find_element(*self.SJM).send_keys(sjm)

    def xzkh(self):
        """选择客户"""
        self.driver.find_element(*self.XZKH).click()  # 点击客户
        sleep(1)
        self.driver.find_element(*self.GXKH).click()  # 勾选客户
        self.driver.find_element(*self.QD).click()  # 点击确定

    def sjje(self,sjje):
        """输入商机金额"""
        self.driver.find_element(*self.SJJE).send_keys(sjje)

    def sjlx(self,sjlx):
        """选择商机类型"""
        SJLX = self.driver.find_element(*self.LX)
        select = Select(SJLX)
        select.select_by_visible_text(sjlx)

    def xzzt(self,zt):
        """选择状态"""
        ZT = self.driver.find_element(*self.XZZT)
        select = Select(ZT)
        select.select_by_visible_text(zt)

    def sjly(self,sjly):
        """选择商机来源"""
        SJLY = self.driver.find_element(*self.LY)
        select = Select(SJLY)
        select.select_by_visible_text(sjly)

    def ydl(self,ydl):
        """输入赢单率"""
        self.driver.find_element(*self.YDL).send_keys(ydl)

    def yjcj(self,yjcjjg):
        """输入预计成交价格"""
        self.driver.find_element(*self.YJCJ).send_keys(yjcjjg)

    def lxsj(self,xclxsj):
        """输入下次联系时间"""
        self.driver.find_element(*self.LXSJ).send_keys(xclxsj)

    def lxnr(self,xclxnr):
        """输入下次联系内容"""
        self.driver.find_element(*self.LXNR).click()
        self.driver.switch_to.alert.accept()  # 点击确定弹框
        self.driver.find_element(*self.LXNR).send_keys(xclxnr)

    def srbz(self,bz):
        """输入备注"""
        self.driver.find_element(*self.BZ).send_keys(bz)

    def djbc(self):
        """点击保存"""
        self.driver.find_element(*self.DJBC).click()